#ifndef     __ERROR_H
#define     __ERROR_H

#include <stdint.h>

namespace utils {

namespace ec {

const uint8_t Ok = 0;
const uint8_t RecvTimeout = 0x01;
const uint8_t LenFail = 0x02;
const uint8_t SumFail = 0x03;
const uint8_t EndFail = 0x04;
const uint8_t MotorTimeout = 0x05;
const uint8_t Invalid = 0x06;
const uint8_t HeadFail = 0x07;

}

struct Error_t {
public:
    Error_t(uint8_t v) : m_val(v) {}
    Error_t() : m_val(ec::Ok) {}

    inline bool is_ok() const {
        return m_val == ec::Ok;
    }

    inline Error_t& operator=(uint8_t val) {
        m_val = val;
        return *this;
    }

    inline operator uint8_t() const {
        return m_val;
    }

    inline operator bool() const {
        return m_val != ec::Ok;
    }

    inline bool operator==(uint8_t val) const {
        return this->m_val == val;
    }

    inline bool operator!=(uint8_t val) const {
        return this->m_val != val;
    }

    inline uint8_t value() const {
        return m_val;
    }

private:
    Error_t(bool v) {}

    uint8_t m_val;
};

}


#endif
